package edu.hgnc.selfEditor;


import edu.hgnc.selfEditor2.Address;
import edu.hgnc.selfEditor2.AddressPropertyConfiguration;
import edu.hgnc.selfEditor2.Customer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.lang.reflect.Constructor;
import java.util.Optional;

/**
 * 测试自定义的属性编辑器
 */
public class JustTest2 {

	private static final Log logger = LogFactory.getLog(JustTest2.class);

	@Test
	public void test01() {
		logger.info("======================================================");
		logger.info("hello,when you see me,that's mean you are test succeed~");
		logger.info("======================================================");
		logger.debug(Optional.ofNullable(null).orElse(1));
	}

	// 使用注解方式实现
	@Test
	public void test02() {
		logger.info("开始执行");
		if (logger.isDebugEnabled()){
			logger.debug("----------------------------------------------------------------------");
			AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
			context.register(AddressPropertyConfiguration.class);
			context.refresh();

			Customer customer = context.getBean(Customer.class);
			logger.debug("customer===>"+ customer);
		}
	}

	@Test
	public void test03() {
		logger.info("开始执行");
		if (logger.isDebugEnabled()){
			logger.debug("----------------------------------------------------------------------");
			AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
			context.register(AddressPropertyConfiguration.class);
			context.refresh();

			Customer customer = context.getBean(Customer.class);
			Customer customer1 = context.getBean(Customer.class);
			logger.debug("customer===>"+ customer);
			logger.debug("customer===>"+ customer1);
		}
	}

	// 反射创建对象
	@Test
	public void test04() throws Exception{
		logger.info("开始执行");
		if (logger.isDebugEnabled()){
			logger.debug("----------------------------------------------------------------------");

			Class<?> aClass = Class.forName("edu.hgnc.selfEditor2.Address");
			Constructor<?> constructor = aClass.getDeclaredConstructor();
			Object o = constructor.newInstance();
			logger.debug("customer===>"+ o);
		}
	}

}
